package com.zhala.web.controller.system;

import com.zhala.common.annotation.Log;
import com.zhala.common.core.controller.BaseController;
import com.zhala.common.core.domain.CommonResult;
import com.zhala.common.core.domain.PageResult;
import com.zhala.common.enums.BusinessType;
import com.zhala.system.domain.ZlSteelPipe;
import com.zhala.system.domain.vo.*;
import com.zhala.system.service.IZlSteelPipeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 管节相关接口
 *
 * @author ssh
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/app/steel-pipe")
public class AppSteelPipeController extends BaseController {
    @Autowired
    private IZlSteelPipeService zlSteelPipeService;

    /**
     * 工序1-生产钢管参数设置
     */
    @Log(title = "生产钢管参数设置", businessType = BusinessType.OTHER)
    @PostMapping("/settings")
    public CommonResult<Boolean> settings(@RequestBody @Valid SteelPipeSettingsReqVO reqVO) {
        return zlSteelPipeService.settings(reqVO);
    }

    /**
     * 工序2-下料工序
     */
    @Log(title = "下料工序", businessType = BusinessType.OTHER)
    @PostMapping("/blanking")
    public CommonResult<Boolean> blanking(@RequestBody @Valid SteelPipeBlankingReqVO reqVO) {
        return zlSteelPipeService.blanking(reqVO);
    }

    /**
     * 工序2-下料工序-修改
     */
    @Log(title = "工序2-下料工序-修改", businessType = BusinessType.OTHER)
    @PostMapping("/blanking-update")
    public CommonResult<Boolean> blankingUpdate(@RequestBody @Valid SteelPipeBlankingReqVO reqVO) {
        return zlSteelPipeService.blankingUpdate(reqVO);
    }

    /**
     * 工序3-卷板工序
     */
    @Log(title = "卷板工序", businessType = BusinessType.OTHER)
    @PostMapping("/coil")
    public CommonResult<Boolean> coil(@RequestBody @Valid SteelPipeCoilReqVO reqVO) {
        return zlSteelPipeService.coil(reqVO,false);
    }

    /**
     * 工序3-卷板工序-修改
     */
    @Log(title = "工序3-卷板工序-修改", businessType = BusinessType.OTHER)
    @PostMapping("/coil-update")
    public CommonResult<Boolean> coilUpdate(@RequestBody @Valid SteelPipeCoilReqVO reqVO) {
        return zlSteelPipeService.coil(reqVO,true);
    }

    /**
     * 工序4-管节组圆工序
     */
    @Log(title = "工序4:管节组圆工序", businessType = BusinessType.OTHER)
    @PostMapping("/plate-circle")
    public CommonResult<Boolean> coil(@RequestBody @Valid SteelPipePlateCircleReqVO reqVO) {
        return zlSteelPipeService.plateCircle(reqVO);
    }

    /**
     * 工序5-纵缝焊接工序
     */
    @Log(title = "工序5-纵缝焊接工序", businessType = BusinessType.OTHER)
    @PostMapping("/weld")
    public CommonResult<Boolean> weld(@RequestBody @Valid SteelPipeWeldReqVO reqVO) {
        return zlSteelPipeService.weld(reqVO,Boolean.FALSE);
    }

    /**
     * 工序5-纵缝焊接工序-修改
     */
    @Log(title = "工序5-纵缝焊接工序-修改", businessType = BusinessType.OTHER)
    @PostMapping("/weld-update")
    public CommonResult<Boolean> weldUpdate(@RequestBody @Valid SteelPipeWeldReqVO reqVO) {
        return zlSteelPipeService.weld(reqVO,Boolean.TRUE);
    }

    /**
     * 报废
     */
    @Log(title = "报废", businessType = BusinessType.OTHER)
    @PostMapping("/scrap")
    public CommonResult<Boolean> scrap(@RequestBody @Valid PipeScrapReqVO reqVO) {
        return zlSteelPipeService.scrap(reqVO);
    }


    /**
     * 月度生成强度折线图
     */
    @GetMapping("/months-statistics")
    public CommonResult<List<PipeMonthStatisticsVO>> monthsStatistics() {
        return zlSteelPipeService.qdStatistics(Boolean.TRUE);
    }


    /**
     * 当月累计管节生产数据统计
     */
    @PostMapping("/statistics")
    public CommonResult<List<PipeStatisticsRespVO>> monthsStatistics(@RequestBody StatisticsReqVO reqVO) {
        return zlSteelPipeService.statistics(reqVO);
    }

    /**
     * 管节已完成数量和报废数量统计 筛选条件跟随列表
     */
    @PostMapping("/status-statistics")
    public CommonResult<StatusStatisticsRespVO> monthsStatistics(@RequestBody StatusReqVO reqVO) {
        return zlSteelPipeService.statusStatistics(reqVO);
    }

    /**
     * 管节待办或已完成列表
     */
    @Log(title = "管节待办或已完成列表", businessType = BusinessType.OTHER)
    @PostMapping("/page")
    public CommonResult<PageResult<List<PipePageRespVO>>> page(@RequestBody @Valid PipePageReqVO reqVO) {
        PageResult<List<PipePageRespVO>> page = zlSteelPipeService.page(reqVO);
        return CommonResult.success(page);
    }

    /**
     * 小管详情
     * type:0:获取基础详情 1:带时间线详情
     */
    @GetMapping("/info")
    public CommonResult<SteelPipeRespVO> info(@RequestParam("id") String id, @RequestParam("type") Integer type) {
        return zlSteelPipeService.info(id, type);
    }

    /**
     * 获取未使用小管信息，用于小管大组
     */
    @GetMapping("/unUsePipe")
    public CommonResult<List<ZlSteelPipe>> unUsePipe() {
        return zlSteelPipeService.unUsePipe();
    }

}
